<?php

use yii\db\Schema;
use yii\db\Migration;

class m180129_030922_add_resource_pack_tables extends Migration
{
    public function up()
    {
        $sql = <<<FINE
drop table if exists {{%resource_pack}};
create table if not exists {{%resource_pack}} (
    id int(11) unsigned not null auto_increment,
    name varchar(64),
    status int(1) not null default 1,
    last_update timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    primary key (id)
)engine=innodb default charset=utf8;

drop table if exists {{%resource_app}};
create table if not exists {{%resource_app}} (
    id int(11) unsigned not null auto_increment,
    name varchar(64),
    resource_pack_id int(11),
    status int(1) not null default 1,
    last_update timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    primary key (id)
)engine=innodb default charset=utf8;

drop table if exists {{%resource_app_adspace_map}};
create table if not exists {{%resource_app_adspace_map}} (
    id int(11) unsigned not null auto_increment,
    app_id int(11) not null,
    adspace_id int(11) not null,
    adspace_type int(1) not null default 3 comment '3 mob adspace, 4 mob video adspace',
    status int(1) not null default 1,
    last_update timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    unique key app_adspace_type (app_id, adspace_id, adspace_type),
    primary key (id)
)engine=innodb default charset=utf8;

FINE;
        $this->execute($sql);
    }

    public function down()
    {
        echo "m180129_030922_add_resource_pack_tables cannot be reverted.\n";

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
